package com.dq.controller.api.merchant.workbench.customer;

import com.dq.exception.customException.AdminException;
import com.dq.controller.api.merchant.in.query.CusssSubscribeQuery;
import com.dq.vo.ListDataVo;
import com.dq.vo.Vo;
import com.dq.domain.subscribe.Subscribe;
import com.dq.service.AllService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/25 0025 13:58:54
 */
@RestController
@RequestMapping("/api/merchant/workbench/customer/subscribe")
@Api(description = "顾客预约记录")
public class CusSubscribeController extends AllService {

    @PostMapping("/list")
    @ApiOperation("多条件查询顾客预约记录")
    public Vo list(@RequestBody @ApiParam("") CusssSubscribeQuery cusSubscribeQuery)throws AdminException{
        if(null==cusSubscribeQuery.getPage() || null==cusSubscribeQuery.getSize() || null==cusSubscribeQuery.getId()){throw new AdminException("缺少必要的请求参数");}

        List<Subscribe> subscribeList = cusSubscribeService.findByWhere(cusSubscribeQuery);
        List<Subscribe.OrgSubscribeListVo> orgSubscribeListVos = new ArrayList<>();
        subscribeList.forEach(subscribe -> {orgSubscribeListVos.add(subscribe.toOrgSubscribeListVo());});

        return new ListDataVo(orgSubscribeListVos, cusSubscribeService.countByWhere(cusSubscribeQuery));
    }


}
